import json

from ronglian_sms_sdk import SmsSDK

accId = '8a216da878005a800178d32ed55d4faf'
accToken = '90db94df0c594f58887a6b86c59812b4'
appId = '8aaf0708780055cd0178d33d58765028'



class Smsutil(object):
    # _instance = None

    def __new__(cls, *args, **kwargs):
        if not hasattr(Smsutil, "_instance"):
            cls._instance = super().__new__(cls, *args, **kwargs)
            cls._instance.sms_sdk = SmsSDK(accId, accToken, appId)

        return cls._instance


    def send_message(self,mobile,datas,tid="1"):
        # sdk = SmsSDK(accId, accToken, appId)
        # tid = '容联云通讯创建的模板'
        # mobile = '手机号1,手机号2'
        # datas = ('变量1', '变量2')
        resp = self.sms_sdk.sendMessage(tid, mobile, datas)
        resp_dict = json.loads(resp)

        if resp_dict.get("statusCode") == "000000":
            print("发送短信成功")
            return 0
        else:
            print("短信发送失败")
            return 1

# if __name__ == "__main__":
#     sms = Smsutil()
#     sms.send_message()
